<template>
    <el-container class="home_container">
        <!--頭部區域-->
        <el-header>
            <div class="header_left">
                <img src="../assets/cat.png" alt="">
                <span>緣分是誰的</span>
            </div>
            <div class="header_right">
                <el-button type="info" @click="logOut">退出</el-button>
            </div>
        </el-header>
        <!--中间区域-->
        <el-container>
            <!--侧边栏-->
            <el-aside :width="isCollapse? '64px':'200px'">
                <div class="toggle_btn">
                    <i :class="isCollapse?'el-icon-s-unfold':'el-icon-s-fold'" @click="toggleCollapse"></i>
                </div>
                <!--侧边栏菜单区-->
                <!--unique-opened="true" 每次只能打开一个菜单-->
                <!-- :collapse="isCollapse": 绑定折叠操作属性-->
                <!-- :collapse-transition="false": 绑定折叠操作动画属性 加上:保证他的值是布尔值-->
                <!--:router="true" 为侧边栏开启路由模式-->
                <!--:default-active="activePath": 将路由路径高亮显示保存到我们的属性中, 其实不保存也一样, 没啥问题-->
                <el-menu background-color="#333744"
                         text-color="#fff"
                         active-text-color="#409EFF"
                         unique-opened
                         :collapse="isCollapse"
                         :collapse-transition="false"
                         :router="true"
                         :default-active="activePath">
                    <!--一级菜单-->
                    <el-submenu v-for="item in menu" :index="item.id+''" :key="item.id">
                        <!--一级菜单模板区域-->
                        <template slot="title">
                            <!--图标-->
                            <i :class="icons[item.id]"></i>
                            <!--文本-->
                            <span>{{item.menuName}}</span>
                        </template>
                        <!--:index 是针对我们的跳转 :router属性的路由模式跳转, 需要在路由文件添加我们的路由-->
                        <el-menu-item v-for="subItem in item.children" @click="saveNavState('/'+subItem.path)"
                                      :key="subItem.id" :index="'/' +subItem.path">
                            <template slot="title">
                                <!--图标-->
                                <i class="el-icon-s-promotion"></i>
                                <!--文本-->
                                <span>{{subItem.menuName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <!--主体-->
            <el-main>
                <router-view/>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "Home",
        data() {
            return {
                menu: [
                    {
                        id: 1,
                        order: 1,
                        menuName: '系统管理',
                        path: 'sysManage',
                        children: [
                            {
                                id: 11,
                                order: 11,
                                menuName: '用户列表',
                                path: 'userList',
                            }, {
                                id: 12,
                                order: 12,
                                menuName: '角色列表',
                                path: 'roleList',
                            }, {
                                id: 13,
                                order: 13,
                                menuName: '权限列表',
                                path: 'permList',
                            }
                        ]
                    },
                    {
                        id: 2,
                        order: 2,
                        menuName: '商品管理',
                        path: 'goodsManage',
                        children: [
                            {
                                id: 21,
                                order: 21,
                                menuName: '商品列表',
                                path: 'goodsList',
                            }, {
                                id: 22,
                                order: 22,
                                menuName: '分类参数',
                                path: 'sortParameter',
                            }, {
                                id: 23,
                                order: 23,
                                menuName: '商品分类',
                                path: 'goodsSort',
                            }]
                    },
                    {
                        id: 3,
                        order: 3,
                        menuName: '订单管理',
                        path: 'orderManage',
                        children: [
                            {
                                id: 31,
                                order: 31,
                                menuName: '订单列表',
                                path: 'orderList',
                            }
                        ]
                    },
                    {
                        id: 4,
                        order: 4,
                        menuName: '数据统计',
                        path: 'dataStatistics',
                        children: [
                            {
                                id: 41,
                                order: 41,
                                menuName: '数据报表',
                                path: 'report',
                            }
                        ]
                    },
                    {
                        id: 9,
                        order: 9,
                        menuName: '其他管理',
                        path: 'otherManage',
                        children: [
                            {
                                id: 91,
                                order: 91,
                                menuName: '其他列表1',
                                path: 'other1List',
                            }, {
                                id: 92,
                                order: 92,
                                menuName: '其他列表2',
                                path: 'other2List',
                            }, {
                                id: 93,
                                order: 93,
                                menuName: '其他列表3',
                                path: 'other3List',
                            }
                        ]
                    }
                ],
                icons: {
                    1: 'iconfont icon-yonghu',
                    2: 'iconfont icon-mima',
                    3: 'iconfont icon-yonghu',
                    4: 'iconfont icon-mima',
                    9: 'iconfont icon-mima'

                },
                /*是否折叠*/
                isCollapse: false,
                // 默认被激活的地址
                activePath: ''
            }
        },
        methods:
            {
                logOut() {
                    window.sessionStorage.clear();
                    this.$router.push('/login');
                }
                ,
                getMenuList() {
                    // TODO
                    // const {data: res} = this.$http.get('menus');
                }
                ,
                toggleCollapse() {
                    // 切换折叠面板
                    this.isCollapse = !this.isCollapse;
                }
                ,
                // 保存我们当前页面的激活路径
                saveNavState(activePath) {
                    this.activePath = activePath;
                    window.sessionStorage.setItem('activePath', activePath);
                }
            }
        ,
        created() {
            this.getMenuList();
            this.activePath = window.sessionStorage.getItem('activePath');
        }
    }
</script>

<style lang="less" scoped>
    .home_container {
        height: 100%;
    }

    .el-header {
        background-color: #373D41;
        display: flex;
        justify-content: space-between;
        padding-left: 0;
        align-items: center;
        color: #FFF;
        font-size: 20px;

        > div {
            display: flex;
            align-items: center;

            span {
                margin-left: 15px;
            }
        }
    }

    .el-aside {
        background-color: #333744;
        /*对齐右边边框线*/

        .el-menu {
            border: none;
        }
    }

    .el-main {
        background-color: #EAEDF1;
    }

    .el-submenu .iconfont {
        vertical-align: middle;
        margin-right: 10px;
        width: 24px;
        text-align: center;
        font-size: 18px;
    }

    .toggle_btn {
        background-color: #4A5064;
        font-size: 10px;
        line-height: 30px;
        color: #FFF;
        text-align: center;

        > i {
            font-size: 24px;
            vertical-align: middle;
        }
    }


</style>
